package dao;

import java.util.LinkedList;
import java.util.List;
import entities.Song;

public class SongDAO {

	private static final SongDAO instance = new SongDAO();
	private List<Song> Songs;
	
	private SongDAO(){
		Songs = new LinkedList<Song>();
		Song cus = null;
		
		cus = Song.newInstance("lyrics", "Rap", 500L, "0.99", "may 2009", "El venao", "3:39", "may 2010", "mp3", 10, "img");
		Songs.add(cus);
		cus = Song.newInstance("lyric", "Rap", 501L, "0.99", "may 2006", "El mellao", "2:30", "may 2005", "mp3", 15, "img");
		Songs.add(cus);
	}
	
	public static SongDAO getInstance() {
		return instance;
	}

	public synchronized Song findSong(Long product_id) {
		Song result = null;
		for (Song s : Songs){
			if (s.getProduct_id().equals(product_id)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addSong(Song obj) throws RecordDuplicateException{
		if (findSong(obj.getProduct_id()) != null){
			throw new RecordDuplicateException("Song with id: " + obj.getProduct_id() + " is already in the db.");
		}
		else {
			Songs.add(obj);
		}
	}

}
